<script src="../media/system/js/mootools-core.js" type="text/javascript"></script>
<script src="../media/system/js/core.js" type="text/javascript"></script>
<form action="index.php?top=page&option=com_frdownload" method="post" name="adminForm" id="adminForm" class="adminform">
<!-- LEFT -->
 <?php echo $this->loadTemplate('search','default') ?>
 <!-- END LEFT -->
 
 <!-- CONTENT -->
 <div id="jm-content">
    <h3 class="jm-title">ダウンロード集</h3>
                <div style="clear: both;"></div>
                <?php
                   
                    $rows=$this->rows;
                    if ($rows !=null)
                    {
                        foreach($rows as $row)
                        {
                ?>
     
                <div class="cc">
                    <h2>
                       	 <?php echo $row->CADM_NAME; ?>
                    </h2>
                
                        <table cellspacing="0" cellpadding="0" width="100%" border="0" class="tb_content">
                        <tbody>
                             <?php
                            if($row->data != null){  
                                
                            foreach($row->data as $k=>$data){   
                            ?>
                            <tr >
                                <td class="col_1">
                                    <?php
                                    //$now = getdate(); 
                                    //echo $now;
                                    $c =date('Y/m/d'); 
                                    $a= $data->DOWI_DATE;
                                    $a = date('Y/m/d', strtotime($a) );
                                    $d=strtotime($c)-strtotime($a);
                                    $num=$d/86400;
                                    $item=bgData::getNumNew();                             
                                    if ($num<=$item)
                                    {
                                        echo '<img src="components/com_frdownload/public/images/icon_new.gif" class="icon"/>';
                                    }
                                    ?>
                                </td>
                                <td class="col_2" >
                                    <?php
                                        $path= $data->DOWI_PATH;
                                        $so=strpos($path,".");
                                        $so=$so+1;
                                        $path=substr($path,$so,4);
                                        if (trim($path)=='pdf')
                                        {
                                            echo '<img src="templates/toppage-BG/images/pdf.png" class="icon"/>';
                                        }
                                        else if(trim($path)=='doc' or (trim($path)=='docx'))
                                        {
                                            echo '<img src="templates/toppage-BG/images/word.png" class="icon"/>';
                                        }
                                         else if(trim($path)=='slsx' or (trim($path)=='xls'))
                                        {
                                            echo '<img src="templates/toppage-BG/images/exel.png" class="icon"/>';
                                        }
                                        else if(trim($path)=='zip')
                                        {
                                            echo '<img src="templates/toppage-BG/images/zip.gif" class="icon"/>';
                                        }
                                        else if(trim($path)=='rar')
                                        {
                                            echo '<img src="templates/toppage-BG/images/rar.png" class="icon"/>';
                                        }
                                        else if(trim($path)=='txt')
                                        {
                                            echo '<img src="templates/toppage-BG/images/txt.png" class="icon"/>';
                                        }
                                        else if(trim($path)=='csv')
                                        {
                                            echo '<img src="templates/toppage-BG/images/csv.png" class="icon"/>';
                                        }
                                        else if(trim($path)=='png' || trim($path)=='gif' || trim($path)=='jpg')
                                        {
                                            echo '<img src="templates/toppage-BG/images/png.png" class="icon"/>';
                                        }
                                        else if(trim($path)=='mp3' || trim($path)=='avi' || trim($path)=='mp4')
                                        {
                                            echo '<img src="templates/toppage-BG/images/mp3.png" class="icon"/>';
                                        }
                                        
                                     ?>
                                   <!-- <img src="components/com_frdownload/public/images/pdficon_small.gif" class="icon"/>-->
                                </td>
                                <?php
                                    $model = $this->getModel();
                                    $file_name = $model->getDowiPath($data->DOWI_CODE);
                                 
                                    //$urlFile = urlencode($file_name);
                                    //$dowi_path  = "download.php?folder=files/com_download&file=".$urlFile; 
                                    $dowi_path  = "download.php?folder=files/com_download&file=".$file_name;  
                                        
                                    //$encode_filename = sha1($file_name);                
                                    //$check_file = "uploads/files/com_download/$encode_filename";
                                    $check_file = "uploads/files/com_download/$file_name";
                                    
                                ?>
                                <td style='width:320px'>
                                <?php
                                    if(file_exists($check_file)){
                                        $size_of_file = HelperBG::filesize_formatted($check_file);  //get size of file
                                ?>
                                    <a href="<?php echo $dowi_path; ?>"><?php echo  $data->DOWI_NAME; ?></a>
                                <?php
                                    }else{
                                ?>
                                    <a href="javascript:alertError();"><?php echo $data->DOWI_NAME; ?></a>
                                <?php
                                
                                    }
                                ?>
                                </td>
                                <td style='padding:0 5px;width:80px'><?php echo  date('Y/m/d', strtotime( $data->DOWI_DATE) );  ?></td>
                                <td style='width:600px;text'><?php echo "(" . $data->DOWI_DESCRIPTION.' '.$size_of_file . ")"; ?></td>
                            </tr>
                            <tr>
                                <td colspan="6"><hr /></td>                        
                            </tr>
                                    <?php
                                    }
                                         ?>
                                     </tbody>
                                </table>
                                        <?php 
                                            }
                                                else{
                                            ?>
                                                <tr>
                                                    <td class="center" colspan="5">データは見つかりませんでした</td>
                                                </tr>
                                    </tbody>
                                </table>
                                            <?php    
                                            }
                                            ?>
                                </div>
                                            <?php
                                             
                                            }
                                        }
                                        else
                                            echo '<center>データは見つかりませんでした</center>';
                                        
                                     ?>
                        </td>
                    </tr>
            <table cellspacing="0" cellpadding="0" width="100%" border="0">
                <tfoot>
        			<tr>
        				<td colspan="15" style="text-align: center;">
        				    <?php echo $this->pagination->getListFooter(); ?>	
                        </td>
        			</tr>
        		</tfoot>
            </table>
      </div>
 
    <input type="hidden" name="task" value=""/>
	<input type="hidden" name="boxchecked" value="0" />  

 </div>
 <!-- END RIGHT -->
 </form>

<script>
    function alertError(){
        /*alert("KHONG TIM THAY FILE");*/
        alert("ファイルを見つかりません。");
    }
</script>

